package com.zzty.txj.controller;

import com.zzty.txj.entity.Question;
import com.zzty.txj.entity.SelfExam;
import com.zzty.txj.service.SelfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/self")
public class SelfController {
    @Autowired
    SelfService selfServiceImpl;


    @ResponseBody
    @RequestMapping(value="/insertTo",method = RequestMethod.POST)
    public Integer insert(SelfExam selfExam) throws Exception {
        System.out.println("selfExam=="+selfExam);
        Integer count = selfServiceImpl.insert(selfExam);
        System.out.println("count== "+count);
        return  count;
    }

    @ResponseBody
    @RequestMapping(value="/checkDate",method = RequestMethod.POST)
    public String checkDate(String date) throws Exception {
        String result = selfServiceImpl.getQuestionIdByDate(date);
        System.out.println("reslut==== "+result);
        return  result;
    }

    @ResponseBody
    @RequestMapping(value="/getContent")
    public Map<String, List<Question>> getContent(String date) throws Exception {
        Map<String,List<Question>> map= new HashMap<>();
        System.out.println("date====="+date);
        map= selfServiceImpl.getContentByDate(date);
        System.out.println("map==== "+map);
        return  map;
    }


    @ResponseBody
    @RequestMapping(value="/getSelfExamId")
    public Integer getSelfExamId(String date) throws Exception {
        Integer selfExamId = selfServiceImpl.getSelfExamId(date);
        System.out.println("selfExamId== "+selfExamId);
        return  selfExamId;
    }
}
